package com.zyj.myapplication.Fragment;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zyj.myapplication.Javabean.Activity;
import com.zyj.myapplication.Model.ActivityModel;
import com.zyj.myapplication.Adapter.ActivityListAdapter;
import com.zyj.myapplication.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class HomeActivityFragment extends Fragment {
    private RecyclerView recyclerView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.activity_home_activity_fragment,container,false);
        recyclerView = (RecyclerView) view.findViewById(R.id.activity_rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
        showDate();
        return view;
    }
    private void showDate(){
        ActivityModel activityModel = new ActivityModel();
        Call<List<Activity>> call = activityModel.getactivitylist();
        call.enqueue(new Callback<List<Activity>>() {
            @Override
            public void onResponse(Call<List<Activity>> call, Response<List<Activity>> response) {
                List<Activity> mDataList = response.body();
                recyclerView.setAdapter(new ActivityListAdapter(HomeActivityFragment.this.getContext(),mDataList));
            }//绑定一个适配器

            @Override
            public void onFailure(Call<List<Activity>> call, Throwable t) {

            }
        });
    }




}
